﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace loginSQL.Pages
{
    public class Page : AbstractPage
    {
        public Page(List<string> dataList,List<PointF> pointArray)
        {
            this.dataList = dataList;
            this.pointArray = pointArray;
            init();
        }
        public override void init()
        {
            for (int i = 0; i < pointArray.Count; i++)
            {
                pointArray[i] = new PointF((pointArray[i].X) * Constants.pixelPerMili.X, (pointArray[i].Y) * Constants.pixelPerMili.Y);
            }
            float minX = 10000,maxX = 0,minY = 10000,maxY = 0;
            foreach (PointF point in pointArray)
            {
                if (point.X < minX)
                    minX = point.X;
                else if (point.X >= maxX)
                    maxX = point.X;

                if (point.Y < minY)
                    minY = point.Y;
                else if (point.X >= maxX)
                    maxY = point.Y;
            }

            this.boundRect = new RectangleF(minX, minY, maxX - minX, maxY - minY);
        }
       
        public override Image getPrintReadyImage()
        {
            this.pageImage = new Bitmap(Constants.backBufferSize.X, Constants.backBufferSize.Y);
            Graphics g = Graphics.FromImage(pageImage);
            g.FillRectangle(Brushes.White, new Rectangle(0, 0, pageImage.Width, pageImage.Height));
            for (int i = 0; i < pointArray.Count; i++)
            {
                //pointArray[i] = new PointF((pointArray[i].X - Constants.offsetMili.X) * Constants.pixelPerMili.X, (pointArray[i].Y - Constants.offsetMili.Y) * Constants.pixelPerMili.Y);                
                PointF print = new PointF(pointArray[i].X + Constants.offsetPixel.X, pointArray[i].Y + Constants.offsetPixel.Y);
                g.DrawString(dataList[i], Constants.f, Brushes.Black,print);
            }
            return this.pageImage;
            
        }

        public override void movePixelX(int moveX)
        {
            for (int i = 0; i < pointArray.Count; i++)
            {
                pointArray[i] = new PointF(pointArray[i].X + moveX, pointArray[i].Y);
            }
        }

        public override void movePixelY(int moveY)
        {
            for (int i = 0; i < pointArray.Count; i++)
            {
                pointArray[i] = new PointF(pointArray[i].X, pointArray[i].Y + moveY);
            }
        }

        public override void movePixelXY(int moveX, int moveY)
        {
            for (int i = 0; i < pointArray.Count; i++)
            {
                pointArray[i] = new PointF(pointArray[i].X + moveX, pointArray[i].Y + moveY);
            }
            this.boundRect = new RectangleF(boundRect.X + moveX, boundRect.Y + moveY, boundRect.Width, boundRect.Height);
        }

        public override void Draw(Graphics g)
        {            
            for (int i = 0; i < pointArray.Count; i++)
            {                
                g.DrawString(dataList[i], Constants.TenPixelFont, Brushes.Black, pointArray[i]);
            }
            //g.DrawRectangle(Pens.Blue, new Rectangle((int) boundRect.X,(int)boundRect.Y,(int)boundRect.Width,(int)boundRect.Height));            
            
        }
       
    }
}
